package com.itheima.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
@Order(2)
public class RecordTimeAspect2 {
    @Pointcut("execution(* com.itheima.service.DeptService.*(..))")
    public void pt(){}

    /*@Around("pt()")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {
        log.info("-------------around-before--------------");
        long begin = System.currentTimeMillis();
        Object proceed = pjp.proceed();
        long end = System.currentTimeMillis();
        long time =  end - begin;
        log.info("执行时间：{}ms",time);
        log.info("-------------around-after--------------");
        return proceed;
    }*/

    @Before("com.itheima.aspect.RecordTimeAspect1.pt()")
    public void before(JoinPoint jp) throws Throwable{
        log.info("-----------------------before2---------------");
    }


    @After("com.itheima.aspect.RecordTimeAspect1.pt()")
    public void after(JoinPoint jp) throws Throwable{
        log.info("-----------------------after2---------------");
    }

    @AfterReturning("com.itheima.aspect.RecordTimeAspect1.pt()")
    public void afterReturning(JoinPoint jp) throws Throwable{
        log.info("-----------------------afterReturning2---------------");
    }
    @AfterThrowing("com.itheima.aspect.RecordTimeAspect1.pt()")
    public void afterThrowing(JoinPoint jp) throws Throwable{
        log.info("-----------------------afterThrowing2---------------");
    }
}
